import App from './App'
import router from './router'
import store from './store'
import demoBlock from './components/demo-block.vue'
// import yjhUi from '../packages/index'
import '../packages/theme-default/lib/index.css'
import api from './api'
import { getDict } from '@/utils/getDict'

// console.log(yjhUi)
const jsencrypt = new JSEncrypt()


Vue.prototype.$ELEMENT = { size: 'small', zIndex: 3000 }

let $vue = window.$vue = new Vue()

// 获取提示语句
// api.getTipsDictionary().then(res => {
//   window.store.commit('setTipsDictionary', window.$plugins.arrayToSet(res, 'value'))
// })

Vue.mixin({
  computed: {
    // 释义字典
    tipsDict () {
      return this.$store.getters.getTips
    }
  },
  methods: {
    // 获取提示
    getTips (key) {
      if (Object.prototype.hasOwnProperty.call(this.tipsDict, key)) {
        return this.tipsDict[key].description
      }
      return ''
    }
  }
})
Vue.prototype.$api = api
Vue.component('demo-block', demoBlock)

api.fetchIdentify().then(pubKey => {
  jsencrypt.setPublicKey(pubKey)
  api.login({
    identifyKey: pubKey,
    companyName: '手机扫菲集团',
    loginName: jsencrypt.encrypt('15116315603'),
    password: jsencrypt.encrypt('123456')
  }).then((data) => {
    localStorage.setItem('session', data.sessionId)
    $plugins.setLStorage('USER_INFO', data)
    
    window.SETING.EXT_TENANT_ID = data.tenantId
    // 首次登陆需要
    getDict().finally(() => {
      new Vue({
        el: '#app',
        store,
        router,
        render: h => h(App)
      })
    })
  }).finally(() => {
    this.loading = false;
  })
}).catch(() => {
  console.log('请求代码报错---------------')
})

